<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>

<head>
    <title>企业列表</title>
</head>

<body>

<div id="wrapper">
    <div class="gray-bg">
        <div class="row m-t-sm">
            <div class="col-lg-12">
                <ol class="breadcrumb f-fl">
                    <li>
                        <i class="fa fa-location-arrow"></i>  <a>企业管理</a>
                    </li>
                    <li class="active">
                        <strong>企业列表</strong>
                    </li>
                </ol>
                <c:if test="${sys_flag}">
                    <span class="navbar-right  m-r m-t-8"><a href="${ctx}/admin/ehm/user/edit" class="btn-primary btn-add "> <i class='fa fa-plus-square-o'></i> 新 增</a></span>
                    <span class="navbar-right  m-r m-t-8"><a href="javascript:void(0)" download onclick="downexcel()" class="btn-primary btn-add "> <i class='fa fa-plus-square-o'></i>模板下载</a></span>
                    <span class="navbar-right  m-r m-t-8"><a href="javascript:void(0)" onclick="divShow()" class="btn-primary btn-add "> <i class='fa fa-plus-square-o'></i>人员导入</a></span>
                </c:if>
            </div>
        </div>
        <div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
                <div class="col-lg-12">
                    <div class="ibox">
                        <div class="ibox-content">
                            <div class="search-area">
                                <form role="form" class="form-inline" id="queryform">
                                    <label for="title">
                                        <select name="status"  class="form-control form-filter" form="queryform" style="width:100%">
                                            <option value="">请选择状态</option>
                                            <option value="10">启用</option>
                                            <option value="20">禁用</option>
                                        </select></label>
                                    <label for="title">
                                        <select name="appStatus"  class="form-control form-filter" form="queryform" style="width:100%">
                                            <option value="">app状态</option>
                                            <option value="0">未登录</option>
                                            <option value="1">已登陆</option>
                                        </select></label>
                                    <label for="title">
                                        <select name="jstatus"  class="form-control form-filter" form="queryform" style="width:100%">
                                            <option value="">在职状态</option>
                                            <option value="0">在职</option>
                                            <option value="1">退休</option>
                                            <option value="2">离职</option>
                                        </select></label>
                                    <label for="title">
                                        <input type="input" placeholder="姓名" name="title"
                                               id="title"
                                               class="form-control form-filter"></label>
                                    <label for="workno">
                                        <input type="input" placeholder="工号" name="workno"
                                               id="workno"
                                               class="form-control form-filter"></label>
                                    <button class="btn btn-primary" type="button" onclick="submitFilter()"> 查询</button>
                                    <button class="btn btn-primary" datatable-clear type="button"> 清除</button>
                                </form>
                            </div>
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered table-hover dataTables" id="data-table"></table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
</div>


<!-- Page-Level Scripts -->
<script>
    $(document).ready(function () {
        var setting = {
            "ajax": {
                "url": "${ctx}/admin/ehm/user/list",
                "type": "POST"
            },
            "columns": [
                {"title": "姓名", "data": "title", "width": "10%", "orderable": false},
                {"title": "工号", "data": "workno", "width": "10%", "orderable": false},
                {"title": "企业名称", "data": "company", "width": "10%", "orderable": false},
                {"title": "所在部门", "data": "dept", "width": "10%", "orderable": false},
                {"title": "手机号", "data": "cellphone", "width": "10%", "orderable": false},
                {"title": "app状态", "data": "appStatus", "width": "10%", "orderable": false},
                {"title": "在职状态", "data": "jstatus", "width": "10%", "orderable": false},
                {"title": "操作", "data": null, "width": "15%", "orderable": false},
            ],
            "columnDefs": [
                {
                    "targets": 5,
                    "render": function (data, type, row, meta) {
                        if (row.appStatus == 0){
                            return "未登录";
                        }else {
                            return "已登录";
                        }
                    }
                },
                {
                    "targets": 6,
                    "render": function (data, type, row, meta) {
                        if (row.jstatus == 0){
                            return "在职";
                        }else if (row.jstatus == 1) {
                            return "退休";
                        }else if (row.jstatus == 2) {
                            return "离职";
                        }else{
                            return "";
                        }
                    }
                },
                {
                    "targets": 7,
                    "render": function (data, type, row, meta) {
                        var statusStr ='';
                        if (data.status == 10){
                            statusStr = "<a class='btn btn-xs default btn-editable' data-opt data-opt-url='${ctx}/admin/ehm/user/status' data-opt-pams='{\"id\":" + data.id + ",\"status\":20}' data-opt-fun='$(\"#data-table\").DataTable().draw();'  > 禁用 </a>";
                        }else {
                            statusStr = "<a class='btn btn-xs default btn-editable' data-opt data-opt-url='${ctx}/admin/ehm/user/status' data-opt-pams='{\"id\":" + data.id + ",\"status\":10}' data-opt-fun='$(\"#data-table\").DataTable().draw();'  >启用  </a>";
                        }
                        return "<a class='btn btn-xs default btn-editable' href='${ctx}/admin/ehm/user/edit?id=" + data.id + "'><i class='fa fa-pencil-square-o'></i> 详情 </a>" +statusStr;
                    },
                    "orderable": false
                }
            ]

        };
        /* Init DataTables */
        $('#data-table').DataTable(ehconfig.get_datatable_config(setting));
        submitFilter = function () {
            $('#data-table').DataTable().draw();
        }
    });

    function downexcel(){
        $.ajax({
            method: "POST",
            url: "${ctx}/admin/ehm/user/excelcreate",
            dataType: "json",
            async: false,
            success: function(response) {
                if (response.code == 0) {
                    console.log(response.path)
                    location.href=response.path;
                }else{
                    parent.layer.msg(response.msg);
                }
            }
        });
    }

    function divShow(){
        parent.layer.open({
            type: 2,
            title: '导入文件',
            shadeClose: true,
            shade: 0.8,
            area: ['800px', '500px'],
            content: '${ctx}/admin/ehm/user/edit/excel'
        });
    }

    function query(){
        $('#data-table').DataTable().draw();
    }

</script>

</body>

</html>
